﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QLNHASACH.DTO;

namespace QLNHASACH.DataAccessLayer.ObjectDAO
{
    class NguoiDungDAO
    {
        public static NguoiDung LayThongTinNguoiDung(string tenDN)
        {
            string sql="SELECT TenDangNhap,MatKhau FROM NGUOIDUNG where TenDangNhap='"+tenDN+"'";
            DataTable dt=DataAccess.GetDataTable(sql);
            NguoiDung nguoiDung=new NguoiDung();
            if (dt.Rows.Count > 0)
            {
                DataRow dataRow=dt.Rows[0];

                nguoiDung.TenDangNhap = dataRow["TenDangNhap"].ToString();
                nguoiDung.MatKhau = dataRow["MatKhau"].ToString();
             //   nguoiDung.HoTen = dataRow["HoTen"].ToString();
             //   nguoiDung.MaNhom = int.Parse(dataRow["MaNhom"].ToString());
             //   nguoiDung.TenNhom = dataRow["TenNhom"].ToString();
            }
            else return nguoiDung = null;
            return nguoiDung;
        }
        //kiem tra ton tai
        public static bool KiemTraTonTai(string tenND)
        {
            string sql="select * from NGUOIDUNG where TenDangNhap='" + tenND + "'";
            if (DataAccess.GetDataTable(sql).Rows.Count > 0)
                return true;
            return false;
        }
        //
        public static bool ThayDoiMatKhau(string tenDN, string matKhauMoi)
        {
            string sql="UPDATE NGUOIDUNG SET MatKhau='" + matKhauMoi + "' WHERE TenDangNhap='" + tenDN + "'";
            if (DataAccess.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
    }
}
